﻿using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;

namespace Client {
    class ClipCursorHelper {

        [DllImport("user32.dll")]
        static extern bool ClipCursor(ref RECT lpRect);

        [DllImport("user32.dll")]
        public static extern bool ClipCursor(IntPtr lpRect);

        //[DllImport("user32.dll", EntryPoint = "GetWindowRect")]
        //extern static int GetWindowRect(int hwnd, ref RECT lpRect);

        public struct RECT {

            public int Left;
            public int Top;
            public int Right;
            public int Bottom;

            public RECT(Int32 left, Int32 top, Int32 right, Int32 bottom) {
                Left = left;
                Top = top;
                Right = right;
                Bottom = bottom;
            }
        }

        /// <summary>
        /// 设置鼠标显示在主屏范围内
        /// </summary>
        /// <returns></returns>

        public static bool SetCursorInPrimaryScreen() {
            Rect screen = SystemParameters.WorkArea;
            RECT rect = new RECT((int)screen.X, (int)screen.Y, (int)screen.Right, (int)screen.Bottom);
            Console.WriteLine(rect);
            return ClipCursor(ref rect);
        }

        /// <summary>
        /// 恢复鼠标显示，可以所以屏幕的任何位置
        /// </summary>
        /// <returns></returns>

        public static bool Default() {
            return ClipCursor(IntPtr.Zero);
        }
    }
}